# Contributor: Bhushan Shah <bshah@kde.org>
# Maintainer: Luca Weiss <luca@z3ntu.xyz>
pkgname=apitrace
pkgver=11.1
pkgrel=2
pkgdesc="Tools for tracing OpenGL, Direct3D, and other graphics APIs"
url="https://apitrace.github.io/"
arch="all"
license="MIT"
depends="python3"
makedepends="
	cmake
	gtest-dev
	libpng-dev
	libx11-dev
	linux-headers
	mesa-dev
	qt5-qtbase-dev
	samurai
	snappy-dev
	zlib-dev
	"
subpackages="$pkgname-doc"
# Update to submodule revision as in https://github.com/apitrace/apitrace/tree/master/thirdparty when updating
_libbacktrace_commit="dedbe13fda00253fe5d4f2fb812c909729ed5937"
source="https://github.com/apitrace/apitrace/archive/$pkgver/apitrace-$pkgver.tar.gz
	https://github.com/ianlancetaylor/libbacktrace/archive/$_libbacktrace_commit/libbacktrace-$_libbacktrace_commit.tar.gz
	no-submodule.patch
	"

prepare() {
	default_prepare

	# Remove bundled libraries, except for some
	rm -rf $(ls -1d thirdparty/* | grep -Ev "(khronos|md5|crc32c|libbacktrace.cmake|support|CMakeLists.txt)")

	# Add bundled libbacktrace
	mv "$srcdir"/libbacktrace-$_libbacktrace_commit \
		thirdparty/libbacktrace
}

build() {
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DENABLE_STATIC_SNAPPY=OFF
	cmake --build build
}

check() {
	cd build
	CTEST_OUTPUT_ON_FAILURE=TRUE ctest
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

sha512sums="
df6dbddc1907dde7eab4ed41009217d9ec8fa7c8273afa39c4a4a97989b94b78043e3f410457d7619054c7c4c429985ac672f8bc0278e3782ae9d81234376e84  apitrace-11.1.tar.gz
39785b8e2764dbfdd2db43ff5d99b4b6d2c75f932530d23e1e7d8f1da1407bed83c0ba9654669756d66d261b3b57083b3a8a1fe7fdb4cfa84bd81ebd9cb6b291  libbacktrace-dedbe13fda00253fe5d4f2fb812c909729ed5937.tar.gz
2f1ca41ab0d9f162f0b52699ab5664ab23e34a79d62ca105a8b6c9154e718e158c26a87aee48ddac66e87295dee7aab968136510afde5716c90e2206bcf14b21  no-submodule.patch
"
